<style type="text/css">
    .hide{display: none;}
    .clear{clear: both;}
    .laydate-time-list{padding-bottom:0;overflow:hidden}
    .laydate-time-list>li{width:50%!important;}
    .laydate-time-list>li:last-child { display: none;}
    .green{color: green;}
    .blue{color: #1E9FFF;}
    .red{color: red;}
    .xian{margin: 5px 0px;height: 1px;width: 100%;clear: both;border-top: 1px dashed #c1c1c1;}
    .h38{height: 38px;line-height: 38px;color: red;}
    .center{text-align: center!important;}
     .layui-table-cell {
         height: 190px;
     }
</style>
<script>
    var baseUrl = "<?php echo $baseUrl; ?>?t=1";
</script>

<div class="layui-row search-row" id="search-box">
    <div class="item">
        <div class="row" style="width: 500px">
            <div class="box">
                <span class="title">类型：</span>
                <div data-key="type" data-type="list" class="search-key list" >
                    <ul>
                        <li><span data-value>全部</span></li>
                        <li><span data-value="10">佣金</span></li>
                        <li><span data-value="20">提现</span></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="row" style="width: 500px">
            <div class="box">
                <span class="title">变更状态：</span>
                <div  data-key="status" data-type="select" class="txt search-key" >
                    <select name="status" lay-filter="status" class="select" style="width: 190px;">
                        <option value="">请选择</option>
                        <option value="10">待审核</option>
                        <option value="20">到账中</option>
                        <option value="30">已到账</option>
                        <option value="40">已拒绝</option>
                        <option value="50">已撤销</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row" style="width: 330px">
            <div class="box">
                <span class="title">筛选时间：</span>
                <div class="txt">
                    <span data-key="created_at" data-type="txt" class="search-key"><input type="text" id="date2" readonly style="width: 250px;" placeholder=""/></span>
                </div>
            </div>
        </div>
    </div>

    <div class="item">
        <div class="row" style="width: 360px;">
            <div class="box">
                <span class="title">关键字查询：</span>
                <div data-key="key" data-type="txt" class="search-key txt">
                    <input type="text" value="" placeholder="订单号/昵称"/>
                </div>
            </div>
        </div>
        <div class="row" style="width: 460px;">
            <div class="btn">
                <button class="layui-btn layui-btn-sm btn-query">查询</button>
                <?php if(Cm::$app->limitPost('/platform/rebate/index','downexport')){ ?>
                    <a href="javascript:;" onclick="app.downexport()" class="layui-btn layui-btn-normal layui-btn-sm">导出</a>
                <?php } ?>
            </div>
        </div>
    </div>
</div>
<table data-url="<?php echo $baseUrl; ?>?action=list"
       data-search="#search-box"
       data-page=""
       data-height="full-380"
       id="data-list"
       lay-filter='data-list' style="display: none;">
    <thead>
    <tr>
        <th width="10%" align="center" field="user">用户</th>
        <th width="8%" align="center" templet="#tpl-type">类型</th>
        <th width="30%" align="center" field="order_number">订单信息</th>
        <th width="7%"  align="center" field="money">金额</th>
        <th width="7%" align="center" field="after_money">操作后金额</th>
        <th width="10%" align="center" templet="#tpl-status">到账状态</th>
        <th width="10%" align="center" field="created_at">创建时间</th>
        <th width="18%" align="center" toolbar="#tpl-cmd">提现审核</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="tpl-status">
    {{# if(d.status==10){ }}
    <span>待审核</span>
    {{# }else if(d.status==20){ }}
    <span class="green">已审核-到账中</span>
      {{# if(d.result_data){}}
            <br><span>{{d.result_data}}</span>
      {{# }}}
    {{# }else if(d.status==30){ }}
    <span class="green">已到账</span>
    {{# }else if(d.status==40){ }}
    <span class="green">已拒绝</span>
    {{# }else if(d.status==50){ }}
    <span class="green">已撤销</span>
    {{# }}}
</script>

<script type="text/html" id="tpl-type">
    {{# if(d.type==10){ }}
    <span>佣金</span>
    {{# }else{ }}
    <span>提现-扣除余额</span>
    {{# }}}
</script>

<script type="text/html" id="tpl-cmd">
    {{# if(d.type==20&&d.status==10){ }}
        <a href="javascript:;" onclick="app.change.list(this,{{d.id}},20)" class="layui-btn layui-btn-normal layui-btn-sm">审核通过</a>
        <a href="javascript:;" onclick="app.change.list(this,{{d.id}},40)" class="layui-btn layui-btn-danger layui-btn-sm">审核拒绝</a>
        <a href="javascript:;" onclick="app.change.list(this,{{d.id}},30)" class="layui-btn layui-btn-warm layui-btn-sm">线下已打款</a>
    {{# }}}
</script>

<script>
    var app = {
        init:function(){
            $('#data-list').table();
            app.form.init();
            var laydate = layui.laydate;
            laydate.render({
                elem: '#date2'
                ,type: 'datetime'
                ,range: '至'
                ,done:function () {
                    setTimeout(function () {
                        $('#data-list').table();
                    },200)
                }
            });
        },
        form: {
            obj: null,
            init: function () {
                var form = layui.form;
                form.render();
                this.obj = form;
            },
            render: function () {
                this.obj.render();
            }
        },
        downexport:function(){
            var url="<?php echo \yii\helpers\Url::to(['/platform/rebate/index','is_export'=>1]) ?>";

            var where = $('#data-list').data('where');

            for(var k in where){
                url+="&"+k+"="+where[k];
            }
            location.href = url;
        },
        change:{
            list:function(e,id,status){
                if(status==30){
                    layer.confirm('务必线下打款后点此操作？', {icon: 3, title:'提示'}
                        , function(index){
                            $.post('/platform/rebate/audit',{id:id,'status':status},function (d) {
                                layer.msg(d.msg);
                                app.init();
                            },'json')
                        }
                    )
                }else{
                    $.post('/platform/rebate/audit',{id:id,'status':status},function (d) {
                        layer.msg(d.msg);
                        app.init();
                    },'json')
                }
            }
        }
    };

    app.init();
</script>